var dateFormat;
var label;
var messages;

function changeSearchName()
{
  document.all.item("searchvalue").value = "";    
  document.all.item("searchvalue1").value = "";    
  document.all.item("searchvalue2").value = "";    
  var searchname = document.all.item("searchnamealias").value;
  var arr = searchname.split("^");  
  var searchtype = arr[1];
  if(document.all.item("spec") != null && document.all.item("searchvalue") != null  && document.all.item("searchvalue1") != null && document.all.item("searchvalue2") != null)
  { 
    if(searchtype == "date" || searchtype == "double" || searchtype == "integer")
    {     
      document.all.item("spec").style.display = "";
      document.all.item("searchvalue").style.display = "none";    
    }else{
      document.all.item("spec").style.display = "none";
      document.all.item("searchvalue").style.display = "";    
    }
  }
}
function summaryPrepare(form,actionvalue,orderbyname)
{
  if(opener == null&& top.topFrame!=null)
  {
    dateformat = top.topFrame.dateformat;
    label = top.topFrame.labelname;
    messages = top.topFrame.message;
  }
  else if(opener != null&&opener.top!=null&&opener.top.topFrame != null)
  {
    dateformat = opener.top.topFrame.dateformat;
    label = opener.top.topFrame.labelname;
    messages = opener.top.topFrame.message;
  }  
  else if(opener != null&&opener.opener!=null&&opener.opener.top!=null&&opener.opener.top.topFrame != null)
  {
    dateformat = opener.opener.top.topFrame.dateformat;
    label = opener.opener.top.topFrame.labelname;
    messages = opener.opener.top.topFrame.message;
  }
  dateformat = top.dateformat;
  var summaryflag = true;
  if(form.searchnamealias != null && form.searchvalue != null && form.searchvalue1 != null && form.searchvalue2 != null)
  { 
  	var valString = form.searchnamealias.value;
    var arr = valString.split("^");  
    form.searchname.value = arr[0];
    var searchtype = arr[1];
    if(searchtype == "date" || searchtype == "Date")
    {
      var val1 = dateTransform(form.searchvalue1.value,'yyyy-MM-dd',dateformat);
      var val2 = dateTransform(form.searchvalue2.value,'yyyy-MM-dd',dateformat);
      if(val1 < 0 || val2 < 0)
      { 
        alert(replaceString(messages.Item("VALUE_MUST_BE_DATE"),"%s",label.Item("L_QuickSearch")));
        form.searchvalue.value = "";
        summaryflag = false;
      }
      else
        form.searchvalue.value = val1 + "^" + val2;
    }
    else if(searchtype == "integer" || searchtype == "Integer")
    {
      if(!isInteger(form.searchvalue1.value) || !isInteger(form.searchvalue2.value))
      { 
        alert(replaceString(messages.Item("VALUE_MUST_BE_INT"),"%s",label.Item("L_QuickSearch")));
        form.searchvalue.value = "";
        summaryflag = false;
      }
      else
        form.searchvalue.value = form.searchvalue1.value + "^" + form.searchvalue2.value;
    }
    else if(searchtype == "double" || searchtype == "Double")
    {
      if(!isNumeric(form.searchvalue1.value) || !isNumeric(form.searchvalue2.value))
      { 
        alert(replaceString(messages.Item("VALUE_MUST_BE_NUMBER"),"%s",label.Item("L_QuickSearch")));
        summaryflag = false;
      }
      else
        form.searchvalue.value = form.searchvalue1.value + "^" + form.searchvalue2.value;
    }
  }
  if(actionvalue == "orderby")
    editform = page_orderby(form,orderbyname);
  else if(actionvalue == "jumppage")
    editform = page_jump(form);
  else if(actionvalue == "pre")
    editform = page_pre(form);
  else if(actionvalue == "next")
    editform = page_next(form);        
  else if(actionvalue == "first")  
    editform = page_first(form);
  else if(actionvalue == "last")
    editform = page_last(form); 
  else if(actionvalue == "search")
    editform = page_search(form); 
  if(summaryflag)  
    return editform;
  else
    return summaryflag;
}
function page_pre(form)
{
  form.pageaction.value="Pre";
  return form;
}
function page_next(form)
{
  form.pageaction.value="Next";
  return form;
}
function page_first(form)
{
  form.pageaction.value="Jump";
  form.jumppage.value = "-2"
  return form;  
}
function page_last(form)
{
  form.pageaction.value="Jump";
  form.jumppage.value = "-1"
  return form;
}
function page_jump(form)
{
  form.pageaction.value="Jump";
  if(form.jumppage.value <= 0)
    form.jumppage.value = 1;
  if(form.jumppage.value - form.totalpage.value > 0)
    form.jumppage.value = form.totalpage.value;
  return form;
}

function page_orderby(form,ordercol)
{
  form.pageaction.value = "OrderBy";
  if(form.orderbycolumn.value.toUpperCase() == ordercol.toUpperCase())
  {
    if(form.orderbytype.value.toUpperCase() == "ASC")
      form.orderbytype.value = "DESC";
    else
      form.orderbytype.value = "ASC";
  }
  else
    form.orderbycolumn.value = ordercol;
  return form;
}
function page_search(form)
{
  form.pageaction.value="OrderBy";
  return form;
}
